﻿// -- FILE ------------------------------------------------------------------
// name       : RtfHtmlSpecialCharConverter.cs
// project    : RTF Framelet
// created    : Jani Giannoudis - 2010.12.01
// language   : c#
// environment: .NET 2.0
// copyright  : (c) 2004-2010 by Itenso GmbH, Switzerland
// --------------------------------------------------------------------------
using System;
using System.Collections.Generic;

namespace Itenso.Rtf.Converter.Html
{

	// ------------------------------------------------------------------------
	public class RtfHtmlSpecialCharConverter
	{

		// ----------------------------------------------------------------------
		public RtfHtmlSpecialCharConverter()
		{
		} // RtfHtmlSpecialCharConverter

		// ----------------------------------------------------------------------
		public RtfHtmlSpecialCharConverter( string settings )
		{
			Settings = settings;
		} // RtfHtmlSpecialCharConverter

		// ----------------------------------------------------------------------
		public string Settings
		{
			get { return settings; }
			set
			{
				settings = value;
				SetupRepresentations();
			}
		} // Settings

		// ----------------------------------------------------------------------
		public bool ContainsRepresentation( RtfVisualSpecialCharKind charKind )
		{
			return representations.ContainsKey( charKind );
		} // GetRepresentation

		// ----------------------------------------------------------------------
		public string GetRepresentation( RtfVisualSpecialCharKind charKind )
		{
			if ( !ContainsRepresentation( charKind ) )
			{
				return null;
			}

			return representations[ charKind ];
		} // GetRepresentation

		// ----------------------------------------------------------------------
		private void SetupRepresentations()
		{
			representations.Clear();
			if ( string.IsNullOrEmpty( settings ) )
			{
				return;
			}

			string[] settingItems = settings.Split( ',' );
			foreach ( string settingItem in settingItems )
			{
				string[] tokens = settingItem.Split( '=' );
				if ( tokens.Length != 2 )
				{
					continue;
				}

				RtfVisualSpecialCharKind charKind = (RtfVisualSpecialCharKind)Enum.Parse( typeof( RtfVisualSpecialCharKind ), tokens[ 0 ] );
				representations.Add( charKind, tokens[ 1 ] );
			}
		} // SetupRepresentations

		// ----------------------------------------------------------------------
		// members
		private readonly Dictionary<RtfVisualSpecialCharKind, string> representations = new Dictionary<RtfVisualSpecialCharKind, string>();
		private string settings;

	} // class RtfHtmlSpecialCharConverter

} // namespace Itenso.Rtf.Converter.Html
// -- EOF -------------------------------------------------------------------
